#include <JXQCore/JThread>
#include <JXQCore/JDebug>
#include <JXQIO/JBuffer>

using namespace JXQ;

int main(int argc, char *argv[])
{
	J_UNUSED(argc);
	J_UNUSED(argv);

	JBuffer buffer;
	buffer.open(JBuffer::ReadWrite);

	int res = buffer.write("hello world");
	jDebug() << res << buffer;

	buffer.seek(JBuffer::SeekSet, 6);
	char readBuf[256] = "";
	res = buffer.read(readBuf, 3);
	jDebug() << res << readBuf;

	memset(readBuf, 0, 256);
	buffer.reset();
	res = buffer.read(readBuf, 255);
	jDebug() << res << readBuf;


	JQueueBuffer qBuffer(10);
	qBuffer.open(JBuffer::ReadWrite);

	res = qBuffer.write("123456", 6);
	jDebug() << res << qBuffer;

	res = qBuffer.write("abcdefg", 7);
	jDebug() << res << qBuffer;

	memset(readBuf, 0, 256);
	res = qBuffer.read(readBuf, 7);
	jDebug() << res << readBuf;

	res = qBuffer.write("FF", 2);
	jDebug() << res << qBuffer;

	memset(readBuf, 0, 256);
	res = qBuffer.read(readBuf, 7);
	jDebug() << res << readBuf;

	res = qBuffer.write("654321", 6);
	jDebug() << res << qBuffer;

	qBuffer.setBufferSize(20);
	jDebug() << qBuffer.size() << qBuffer.bytesAvailable() << qBuffer;
	qBuffer.setBufferSize(5);
	jDebug() << qBuffer.size() << qBuffer.bytesAvailable() << qBuffer;

	JQueueBuffer qBuffer2;
	qBuffer2.open(JBuffer::ReadWrite);

	res = qBuffer2.write("123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789\n"
						 "123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789\n"
						 "123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789\n"
						 "123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789\n"
						 "123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789",
						 454);
	jDebug() << res << qBuffer2;

	return 0;
}
